const getters = {
  user_id: state => state.user.user_id,
  user_email: state => state.user.user_email,
  user_phone_number: state => state.user.user_phone_number,
  user_nickname: state => state.user.user_nickname,
  user_avatar: state => state.user.user_avatar,
  user_roles: state => state.user.user_roles,
  user_group: state => state.user.user_group,
  user_permissions: state => state.user.user_permissions,
  constRoutes: state => state.permission.constRoutes,
  asyncRoutes: state => state.permission.asyncRoutes,
  projectData: state => state.h5editor.projectData,
  activePageUUID: state => state.h5editor.activePageUUID,
  activeElementUUID: state => state.h5editor.activeElementUUID,
  currentHistoryIndex: state => state.h5editor.currentHistoryIndex,
  activeAttrEditCollapse: state => state.h5editor.activeAttrEditCollapse,
  currentPageIndex: state => {
    if (!state.h5editor.projectData.pages) {
      return -1
    }
    return state.h5editor.projectData.pages.findIndex(v => { return v.uuid === state.h5editor.activePageUUID })
  },
  activeElementIndex: state => {
    if (!state.h5editor.projectData.pages) {
      return -1
    }
    const currentPageIndex = state.h5editor.projectData.pages.findIndex(v => { return v.uuid === state.h5editor.activePageUUID })
    if (currentPageIndex === -1) {
      return -1
    }
    return state.h5editor.projectData.pages[currentPageIndex].elements.findIndex(v => { return v.uuid === state.h5editor.activeElementUUID })
  },
  activePage: state => {
    if (!state.h5editor.projectData.pages || !state.h5editor.activePageUUID) {
      return { commonStyle: {}, config: {}}
    }
    return state.h5editor.projectData.pages.find(v => { return v.uuid === state.h5editor.activePageUUID })
  },
  activeElement: state => {
    if (!state.h5editor.projectData.pages) {
      return { commonStyle: {}, propsValue: {}}
    }
    const currentPageIndex = state.h5editor.projectData.pages.findIndex(v => { return v.uuid === state.h5editor.activePageUUID })
    if (currentPageIndex === -1) {
      return { commonStyle: {}, propsValue: {}}
    }
    return state.h5editor.projectData.pages[currentPageIndex].elements.find(v => { return v.uuid === state.h5editor.activeElementUUID })
  },
  canUndo: state => {
    return state.h5editor.currentHistoryIndex > 0
  },
  canRedo: state => {
    return state.h5editor.historyCache.length > state.h5editor.currentHistoryIndex + 1
  }

}
export default getters
